package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.TravelCollection;
import cn.wolfcode.trip.base.query.TravelCollectionQuery;
import cn.wolfcode.trip.base.query.TravelPaperQuery;
import cn.wolfcode.trip.base.service.ITravelCollectionService;
import cn.wolfcode.trip.base.service.ITravelPaperContentService;
import cn.wolfcode.trip.base.service.ITravelPaperService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("travelCollection")
public class TravelCollectionController {
    @Autowired
    private ITravelCollectionService collectionService;


    @RequestMapping("/save")
    public JSONResult save(Long userId,Long travelId){
        JSONResult result = new JSONResult();
        try {
            collectionService.save(userId,travelId);
        } catch (Exception e) {
            result.mark(e.getMessage());
        }
        return result;
    }
    @RequestMapping("/get")
    public JSONResult get(Long userId, Long travelId){
        JSONResult result = new JSONResult();
        try {
            TravelCollection travelCollection = collectionService.get(userId, travelId);
            if (travelCollection==null){
                result.mark("不存在");
            }
        } catch (Exception e) {
            result.mark(e.getMessage());
        }
        return result;
    }


    @RequestMapping("/list")
    public Object list(@ModelAttribute("qo")TravelCollectionQuery qo, Model model){

        return collectionService.list(qo);
    }


    @RequestMapping("/delete")
    public JSONResult delete(Long userId,Long travelId){
        JSONResult result = new JSONResult();
        try {
            collectionService.delete(userId,travelId);
        } catch (Exception e) {
            result.mark(e.getMessage());
        }
        return result;
    }

}
